//package com.rui.study.micro.goods.test;
//
//import com.rui.study.commons.model.Result;
//import com.rui.study.micro.common.support.Advisor;
//import com.rui.study.micro.common.support.JDKDynamicProxy;
//import com.rui.study.micro.common.support.TargetSource;
//import com.rui.study.micro.common.http.AbstractConcurrentRequest;
//import com.rui.study.micro.common.http.AbstractConcurrentRequest.AggregationResult;
//import com.rui.study.micro.common.http.GoodsConcurrentRequest;
//import static com.rui.study.micro.common.http.GoodsConcurrentRequest.NOT_GETTING_GOODS_THREADS;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.RequestEntity;
//
//import java.net.URI;
//import java.net.URISyntaxException;
//import java.util.LinkedList;
//
//
//public class Main implements Test {
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
//
//    @Override
//    public void testConcurrentModGoodsStock() {
//        AbstractConcurrentRequest request = new GoodsConcurrentRequest(110);
//
//        try {
//            URI uri = new URI("http://study.rui.pub:8180/goods/goods/modGoodsStock?goodsId=0000000003&count=-1");
//            // 并发请求
//            AggregationResult aggregation = request.concurrencyExchange(
//                    new RequestEntity(HttpMethod.GET, uri), Result.class);
//            // 处理结果
//            LinkedList<String> r = (LinkedList<String>) aggregation.getAttribute(NOT_GETTING_GOODS_THREADS);
//            for (String threadName : r) {
//                LOGGER.info("Not getting goods thread: {}", threadName);
//            }
//            LOGGER.info("Not getting goods threads' count is: {}", r.size());
////            LinkedList<ResponseEntity<?>> r = (LinkedList<ResponseEntity<?>>) aggregation.getAttribute(DEFAULT_AGGREGATION_RESULT);
////            for (ResponseEntity res : r) {
////                Result responseObject = (Result) res.getBody();
////                String status = responseObject.getStatus();
////                String desc = responseObject.getMessage();
////                LOGGER.info("Status: {}, Desc: {}", status, desc);
////            }
//
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        }
//    }
//
//
//    /**************************************************
//     *                  INNER CLASS                   *
//     **************************************************/
//
//    private class InternalAdvisor implements Advisor {
//
//        private long startTime;
//
//        private long endTime;
//
//        @Override
//        public Object before() {
//            startTime = System.currentTimeMillis();
//            return null;
//        }
//
//        @Override
//        public Object after() {
//            endTime = System.currentTimeMillis();
//            double duration = (endTime - startTime) / 1000D;
//            LOGGER.info("Duration: [{}s]", duration);
//            return null;
//        }
//
//        @Override
//        public Object onException() {
//            return null;
//        }
//
//        @Override
//        public Object onFinal() {
//            return null;
//        }
//
//    }
//
//    /**************************************************
//     *                     MAIN                       *
//     **************************************************/
//    public static void main(String[] args) {
//        Main main = new Main();
//        JDKDynamicProxy jdkDynamicProxy = new JDKDynamicProxy(new TargetSource(main, Test.class), main.new InternalAdvisor());
//        Test test = (Test) jdkDynamicProxy.getProxy();
//
//        test.testConcurrentModGoodsStock();
//    }
//
//}
